package com.ias.agdis_r.adapter;

//import android.support.v7.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ias.agdis_r.R;
import com.ias.agdis_r.terminalmanager.restful.workgroup.vo.Member;
import com.ias.agdis_r.view.OnRecyclerviewItemClickListener;

import java.util.List;

/**
 * Created by xr.g on 2018/4/9.
 */

public class UnselectedWorkGroupMemberAdapter extends RecyclerView.Adapter<UnselectedWorkGroupMemberAdapter.ViewHolder> implements View.OnClickListener {
    private List<Member> allMember;
    private OnRecyclerviewItemClickListener onItemClickListener;

    public UnselectedWorkGroupMemberAdapter(List<Member> allMember) {
        this.allMember = allMember;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_unselect_work_group_member, parent, false);
        view.setOnClickListener(this);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Member member = allMember.get(position);
        holder.userNo.setText(member.getMember_usno());
        holder.userName.setText(member.getMember_name());
        holder.itemView.setTag(position);
    }

    @Override
    public int getItemCount() {
        if (null != allMember) {
            return allMember.size();
        } else {
            return 0;
        }
    }

    @Override
    public void onClick(View v) {
        if (null != onItemClickListener) {
            onItemClickListener.onItemClick(v, (Integer) v.getTag());
        }
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        private TextView userNo, userName;

        public ViewHolder(View view) {
            super(view);
            userName = (TextView) view.findViewById(R.id.tv_userName);
            userNo = (TextView) view.findViewById(R.id.tv_userNo);
        }
    }

    public void setOnItemClickListener(OnRecyclerviewItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }
}
